<template>
  <el-config-provider :locale="lang">
    <router-view />
  </el-config-provider>
  <h1></h1>
</template>

<script setup>
import { generateNewStyle, writeNewStyle } from '@/utils/theme'
import { computed } from 'vue'
import { useStore } from 'vuex'
import { watchSwitchLang } from '@/utils/i18n'

import zhCn from 'element-plus/es/locale/lang/zh-cn'
import en from 'element-plus/lib/locale/lang/en'

const store = useStore()

// 处理语言切换
const lang = computed(() => store.getters.language === 'zh' ? zhCn : en)
generateNewStyle(store.getters.mainColor).then(newStyleText => {
  writeNewStyle(newStyleText)
})

watchSwitchLang(() => {
  if (store.getters.token) {
    store.dispatch('user/getUserInfo')
  }
})

</script>

<style></style>
